import type { FcPageConfig } from '@/types/fcform'
import { createFormItems } from './edit/formItems.ts'
import { createRules } from './edit/rules.ts'
import { createColums } from './table/columns.ts'

export function usePageConfig(): FcPageConfig {
  return {
    KEY: 'publicId',
    pageProps: {
      tools: {
        add: true,
        del: false,
      },
    },
    table: {
      getApi: '/admin/param/page',
      delApi: {
        api: '/admin/param',
        method: 'delete',
        isArray: true,
      },
      dataMap: (data) => {
        return data.map((el) => {
          if (el.publicKey.includes('NUMBER')) {
            el.price = Number(el.publicValue)
          }
          return el
        })
      },
      initForm: {
        size: 20,
        publicType: '0',
      },
      createColums,
    },
    edit: {
      default: {
        width: 700,
        addApi: '/admin/param',
        editApi: {
          api: '/admin/param',
          method: 'put',
        },
        defaultValue: {
          publicName: '',
          publicKey: '',
          publicValue: '',
          price: null,
        },
        createItems: createFormItems,
        createRule: createRules,
      },
    },
  }
}
